package View;

import java.util.Date;
import javax.swing.JFrame;

/**
 *
 * @author Tiago
 */
public class PesquisaInjecaoView extends javax.swing.JDialog {
    
    private PrincipalView principalView;
    
    public PesquisaInjecaoView(java.awt.Frame parent, boolean modal, PrincipalView p) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo( null );
        
        principalView = p;
    }

    private PesquisaInjecaoView(JFrame jFrame, boolean b) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpPesquisaInjecaoData = new javax.swing.JPanel();
        dfPesquisaInjecaoDataInicial = new net.sf.nachocalendar.components.DateField();
        dfPesquisaInjecaoDataFinal = new net.sf.nachocalendar.components.DateField();
        lbPesquisaInjecaoDataInicial = new javax.swing.JLabel();
        lbPesquisaInjecaoDataFinal = new javax.swing.JLabel();
        jpPesquisaInjecaoBotao = new javax.swing.JPanel();
        btConfirmar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jpPesquisaInjecaoData.setBorder(javax.swing.BorderFactory.createTitledBorder("Selecione o intervalo"));

        dfPesquisaInjecaoDataInicial.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                dfPesquisaInjecaoDataInicialAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        dfPesquisaInjecaoDataFinal.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                dfPesquisaInjecaoDataFinalAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        lbPesquisaInjecaoDataInicial.setText("Data Inicial");

        lbPesquisaInjecaoDataFinal.setText("Data Final");

        javax.swing.GroupLayout jpPesquisaInjecaoDataLayout = new javax.swing.GroupLayout(jpPesquisaInjecaoData);
        jpPesquisaInjecaoData.setLayout(jpPesquisaInjecaoDataLayout);
        jpPesquisaInjecaoDataLayout.setHorizontalGroup(
            jpPesquisaInjecaoDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPesquisaInjecaoDataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpPesquisaInjecaoDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dfPesquisaInjecaoDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPesquisaInjecaoDataInicial))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jpPesquisaInjecaoDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dfPesquisaInjecaoDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPesquisaInjecaoDataFinal))
                .addContainerGap())
        );
        jpPesquisaInjecaoDataLayout.setVerticalGroup(
            jpPesquisaInjecaoDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPesquisaInjecaoDataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpPesquisaInjecaoDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPesquisaInjecaoDataInicial)
                    .addComponent(lbPesquisaInjecaoDataFinal))
                .addGap(2, 2, 2)
                .addGroup(jpPesquisaInjecaoDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(dfPesquisaInjecaoDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dfPesquisaInjecaoDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(62, Short.MAX_VALUE))
        );

        jpPesquisaInjecaoBotao.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        btConfirmar.setText("Confirmar");
        btConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btConfirmarActionPerformed(evt);
            }
        });

        btCancelar.setText("Cancelar");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpPesquisaInjecaoBotaoLayout = new javax.swing.GroupLayout(jpPesquisaInjecaoBotao);
        jpPesquisaInjecaoBotao.setLayout(jpPesquisaInjecaoBotaoLayout);
        jpPesquisaInjecaoBotaoLayout.setHorizontalGroup(
            jpPesquisaInjecaoBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPesquisaInjecaoBotaoLayout.createSequentialGroup()
                .addGap(62, 62, 62)
                .addComponent(btConfirmar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpPesquisaInjecaoBotaoLayout.setVerticalGroup(
            jpPesquisaInjecaoBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPesquisaInjecaoBotaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpPesquisaInjecaoBotaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btConfirmar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpPesquisaInjecaoBotao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpPesquisaInjecaoData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpPesquisaInjecaoData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jpPesquisaInjecaoBotao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void dfPesquisaInjecaoDataInicialAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_dfPesquisaInjecaoDataInicialAncestorAdded

    }//GEN-LAST:event_dfPesquisaInjecaoDataInicialAncestorAdded

    private void dfPesquisaInjecaoDataFinalAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_dfPesquisaInjecaoDataFinalAncestorAdded
        // TODO add your handling code here:
    }//GEN-LAST:event_dfPesquisaInjecaoDataFinalAncestorAdded

    private void btConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConfirmarActionPerformed
        if(principalView != null){
            principalView.adicionarDataPesquisa((Date)dfPesquisaInjecaoDataInicial.getValue(), (Date)dfPesquisaInjecaoDataFinal.getValue());
            this.dispose();
        }
    }//GEN-LAST:event_btConfirmarActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btCancelarActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated

    }//GEN-LAST:event_formWindowActivated

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PesquisaInjecaoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PesquisaInjecaoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PesquisaInjecaoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PesquisaInjecaoView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                PesquisaInjecaoView dialog = new PesquisaInjecaoView(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btConfirmar;
    private net.sf.nachocalendar.components.DateField dfPesquisaInjecaoDataFinal;
    private net.sf.nachocalendar.components.DateField dfPesquisaInjecaoDataInicial;
    private javax.swing.JPanel jpPesquisaInjecaoBotao;
    private javax.swing.JPanel jpPesquisaInjecaoData;
    private javax.swing.JLabel lbPesquisaInjecaoDataFinal;
    private javax.swing.JLabel lbPesquisaInjecaoDataInicial;
    // End of variables declaration//GEN-END:variables
}
